<html><head><title>Json.pb</title></head>
<body bgcolor="#EFF1F0" link="#3A3966" vlink="#000000" alink="#000000">
<pre><font face="Courier New, Courier, mono"size="2"><font color="#3A3966">;
</font><font color="#3A3966">; ------------------------------------------------------------
</font><font color="#3A3966">;
</font><font color="#3A3966">;   PureBasic - Json
</font><font color="#3A3966">;
</font><font color="#3A3966">;    (c) Fantaisie Software
</font><font color="#3A3966">;
</font><font color="#3A3966">; ------------------------------------------------------------
</font><font color="#3A3966">;
</font>
<font color="#924B72">#JSON_Create</font> = 0
<font color="#924B72">#JSON_Parse</font> = 1


<font color="#3A3966">; Build JSON data from scratch
</font><font color="#3A3966">;
</font><b><font color="#3A3966">If</font></b> <font color="#3A3966">CreateJSON</font>(<font color="#924B72">#JSON_Create</font>)
  Person =<font color="#3A3966"> SetJSONObject</font>(<font color="#3A3966">JSONValue</font>(<font color="#924B72">#JSON_Create</font>))
<font color="#3A3966">  SetJSONString</font>(<font color="#3A3966">AddJSONMember</font>(Person, &quot;FirstName&quot;), &quot;John&quot;)
<font color="#3A3966">  SetJSONString</font>(<font color="#3A3966">AddJSONMember</font>(Person, &quot;LastName&quot;), &quot;Smith&quot;)
<font color="#3A3966">  SetJSONInteger</font>(<font color="#3A3966">AddJSONMember</font>(Person, &quot;Age&quot;), 42)
  
  Values =<font color="#3A3966"> SetJSONArray</font>(<font color="#3A3966">AddJSONMember</font>(Person, &quot;Values&quot;))
  <b><font color="#3A3966">For</font></b> i = 1 <b><font color="#3A3966">To</font></b> 5
<font color="#3A3966">    SetJSONInteger</font>(<font color="#3A3966">AddJSONElement</font>(Values),<font color="#3A3966"> Random</font>(256))
  <b><font color="#3A3966">Next</font></b> i
  
  <b><font color="#3A3966">Debug</font></b> &quot;---------- Compact format ----------&quot;
  <b><font color="#3A3966">Debug</font></b> &quot;&quot;
  <b><font color="#3A3966">Debug</font></b> <font color="#3A3966">ComposeJSON</font>(<font color="#924B72">#JSON_Create</font>)
  <b><font color="#3A3966">Debug</font></b> &quot;&quot;
  <b><font color="#3A3966">Debug</font></b> &quot;---------- Pretty-Printed format ----------&quot;
  <b><font color="#3A3966">Debug</font></b> &quot;&quot;
  <b><font color="#3A3966">Debug</font></b> <font color="#3A3966">ComposeJSON</font>(<font color="#924B72">#JSON_Create</font>, <font color="#924B72">#PB_JSON_PrettyPrint</font>)
  <b><font color="#3A3966">Debug</font></b> &quot;&quot;
<b><font color="#3A3966">EndIf</font></b>


<font color="#3A3966">; Read JSON data from a string
</font><font color="#3A3966">;
</font>Input$ = &quot;[1, 3, 5, 7, null, 23, 25, 27]&quot;
<b><font color="#3A3966">If</font></b> <font color="#3A3966">ParseJSON</font>(<font color="#924B72">#JSON_Parse</font>, Input$)
  <b><font color="#3A3966">NewList</font></b> <font color="#3A3966">Numbers</font>()
<font color="#3A3966">  ExtractJSONList</font>(<font color="#3A3966">JSONValue</font>(<font color="#924B72">#JSON_Parse</font>),<font color="#3A3966"> Numbers</font>())
  
  <b><font color="#3A3966">Debug</font></b> &quot;---------- Extracting values ----------&quot;
  <b><font color="#3A3966">Debug</font></b> &quot;&quot;
  <b><font color="#3A3966">ForEach</font></b> <font color="#3A3966">Numbers</font>()
    <b><font color="#3A3966">Debug</font></b> <font color="#3A3966">Numbers</font>()
  <b><font color="#3A3966">Next</font></b> 
<b><font color="#3A3966">EndIf</font></b>


</font></pre>
</body></html>
